﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Departments.aspx.cs" Inherits="Departments" Trace="false" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
    <script type="text/javascript">
        function BlockUI(elementID) {
            var prm = Sys.WebForms.PageRequestManager.getInstance();
            prm.add_beginRequest(function () {
                $("#" + elementID).block({ message: '<table align = "center" class="StatusBar"><tr><td>' +
     '<img src="loadingAnim.gif"/></td></tr></table>',
                    css: {},
                    overlayCSS: { backgroundColor: '#000000', opacity: 0.6, border: '3px solid #63B2EB'
                    }
                });
            });

            prm.add_endRequest(function () {
                $("#" + elementID).unblock();
            });
        }

        $(document).ready(function () {
            BlockUI("dvGrid");
            $.blockUI.defaults.css = {};
        });
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="Server">
    <asp:ScriptManager runat="server" />
    <h1 id="itemListTitle" runat="server" style="text-align: center; text-decoration: underline;
        text-transform: capitalize; font-size: xx-large; font-weight: bolder; margin-bottom: 25px;">
        Departments options:</h1>
    <div id="dvGrid" style="padding-top: 10px; padding-bottom: 10px; width: 100%">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:GridView ID="gvDepartments" runat="server" Width="100%" AutoGenerateColumns="False"
                    Font-Size="11pt" AlternatingRowStyle-BackColor="#C2D69B" HeaderStyle-BackColor="green"
                    AllowPaging="True" ShowFooter="True" OnPageIndexChanging="gvDepartments_PageIndexChanging"
                    OnRowEditing="gvDepartments_RowEditing" OnRowUpdating="gvDepartments_RowUpdating"
                    OnRowCancelingEdit="gvDepartments_RowCancelingEdit" BackColor="White" BorderColor="#999999"
                    BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical"
                    ShowHeaderWhenEmpty="true">
                    <Columns>
                        <asp:TemplateField ItemStyle-Width="60px" HeaderText="Dept. ID">
                            <ItemTemplate>
                                <asp:Label ID="lblDepartmentID" runat="server" Text='<%# Eval("id")%>'></asp:Label>
                            </ItemTemplate>
                            <FooterTemplate>
                                <asp:Label ID="lblDepartmentIDFoot" Text='<%# Eval("id")%>' runat="server" />
                            </FooterTemplate>
                            <ItemStyle Width="60px" />
                        </asp:TemplateField>
                        <asp:TemplateField ItemStyle-Width="100px" HeaderText="Name">
                            <ItemTemplate>
                                <asp:Label ID="lblName" runat="server" Text='<%# Eval("name")%>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="txtName" Width="80px" runat="server" Text='<%# Eval("name")%>'></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Department Name field is required!"
                                    ControlToValidate="txtName" ValidationGroup="EditGroup" ForeColor="Red">*</asp:RequiredFieldValidator>
                            </EditItemTemplate>
                            <FooterTemplate>
                                <asp:TextBox ID="txtName" runat="server" Width="80"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Department Name field is required!"
                                    ControlToValidate="txtName" ValidationGroup="AddGroup" ForeColor="Red">*</asp:RequiredFieldValidator>
                            </FooterTemplate>
                            <ItemStyle Width="100px" />
                        </asp:TemplateField>
                        <asp:TemplateField ItemStyle-Width="430px" HeaderText="URL">
                            <ItemTemplate>
                                <asp:Label ID="lblUrl" runat="server" Text='<%# Eval("url")%>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="txtUrl" Width="400px" runat="server" Text='<%# Eval("url")%>'></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Department URL field is required!"
                                    ControlToValidate="txtUrl" ValidationGroup="EditGroup" ForeColor="Red">*</asp:RequiredFieldValidator>
                            </EditItemTemplate>
                            <FooterTemplate>
                                <asp:TextBox ID="txtUrl" Width="400px" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Department URL field is required!"
                                    ControlToValidate="txtUrl" ValidationGroup="AddGroup" ForeColor="Red">*</asp:RequiredFieldValidator>
                            </FooterTemplate>
                            <ItemStyle Width="430px" />
                        </asp:TemplateField>
                        <asp:TemplateField ItemStyle-Width="65px">
                            <ItemTemplate>
                                <asp:Button ID="lnkRemove" runat="server" CommandArgument='<%# Eval("id")%>' OnClientClick="return confirm('Are you sure you want to delete this item?')"
                                    Text="Delete" OnClick="DeleteDepartment" Width="100%"></asp:Button>
                            </ItemTemplate>
                            <FooterTemplate>
                                <asp:Button ID="btnAdd" ValidationGroup="AddGroup" runat="server" Text="Add" OnClick="AddNewDepartment"
                                    Width="100%" />
                            </FooterTemplate>
                            <ItemStyle Width="65px" />
                        </asp:TemplateField>
                        <asp:CommandField ValidationGroup="EditGroup" ShowEditButton="True" ButtonType="Button"
                            ItemStyle-Width="180px" ItemStyle-HorizontalAlign="Center" />
                    </Columns>
                    <AlternatingRowStyle BackColor="#CCCCCC" />
                    <FooterStyle BackColor="#CCCCCC" />
                    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                    <SortedAscendingCellStyle BackColor="#F1F1F1" />
                    <SortedAscendingHeaderStyle BackColor="#808080" />
                    <SortedDescendingCellStyle BackColor="#CAC9C9" />
                    <SortedDescendingHeaderStyle BackColor="#383838" />                    
                </asp:GridView>
                <asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="AddGroup" ForeColor="Red" Font-Bold="true" />
                <asp:ValidationSummary ID="ValidationSummary2" runat="server" ValidationGroup="EditGroup" ForeColor="Red" Font-Bold="true" />
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="gvDepartments" />
            </Triggers>
        </asp:UpdatePanel>
    </div>
</asp:Content>
